package main

import (
	"fmt"
)

//func maxArea(height []int) int {
//	if len(height) < 2 {
//		return 0
//	}
//	volume := 0
//	for i := 0; i < len(height); i++ {
//		for j := i + 1; j < len(height); j++ {
//			if volume < min(height[i], height[j])*(j-i) {
//				volume = min(height[i], height[j]) * (j - i)
//			}
//		}
//	}
//	return volume
//
//}

func maxArea(height []int) (ans int) {
	left, right := 0, len(height)-1
	for left < right {
		area := (right - left) * min(height[left], height[right])
		ans = max(ans, area)
		if height[left] < height[right] {
			left++
		} else {
			right--
		}
	}
	return
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	fmt.Println("49 :   ", maxArea([]int{1, 8, 6, 2, 5, 4, 8, 3, 7}))
	fmt.Println("1 :   ", maxArea([]int{1, 1}))
	fmt.Println("17 :   ", maxArea([]int{2, 3, 4, 5, 18, 17, 6}))
	fmt.Println("32 :   ", maxArea([]int{4, 7, 2, 3, 8, 2, 1, 1, 4}))
}
